package top.kaoshanji.p1ch02a;

import lombok.extern.slf4j.Slf4j;
import org.jasypt.encryption.StringEncryptor;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/5/17 19:35
 */
@Slf4j
@SpringBootTest
public class JasyptTest {

    @Autowired
    private StringEncryptor stringEncryptor;

    // 代码清单test-p1ch02a-68页c：加密测试类
    @Test
    public void encrypt() {

        // 对这两个属性值进行加密
        String userNameEnc = stringEncryptor.encrypt("userName1x");
        String passWordEnc = stringEncryptor.encrypt("passWord2p");

        log.info("test username encrypt is {}", userNameEnc);
        log.info("test password encrypt is {}", passWordEnc);

        // 解密
        log.info("test username is {}", stringEncryptor.decrypt(userNameEnc));
        log.info("test password is {}", stringEncryptor.decrypt(passWordEnc));
    }

}
